/**
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */

import { Pipe, PipeTransform } from '@angular/core';

import { isNil } from 'ng-zorro-antd/core/util';

/**
 * @deprecated v17.0.0 -使用 Nullish 合并运算符 (??) 而不是 `NzSafeNullPipe`。
 */
@Pipe({
  name: 'nzSafeNull',
  standalone: true
})
export class NzSafeNullPipe implements PipeTransform {
  /**
  * 转换类型T的值，如果值为空，则返回replace参数指定的字符串
  * @param value 需要转换的值
  * @param replace 值为空时返回的字符串
  * @returns 转换后的值或者字符串
  */
  transform<T>(value: T, replace: string = ''): T | string {
    if (isNil(value)) {
      return replace;
    }
    return value;
  }
}
